<?php
/*
Plugin Name: URL filter 
Plugin URI: http://www.xys-reader.org/blogs
Description: Change the url text to hyperlink automatically.
Version: 0.1 
Author: Liu Xuefeng
Author URI: http://www.xys-reader.org/blogs/sys_admin
*/

add_filter('the_content', 'the_content_url_filter');
add_filter('get_comment_text', 'the_content_url_filter');
function the_content_url_filter($content) {
        //return preg_replace( '/[^\"\'=]http:\/\/([^\s<\n]*)/i' ," <a href=\"http://$1\">http://$1</a>", $content); 
	//return preg_replace_callback( '/([^>\"\'=]{1}|pre>|p>|br>)http:\/\/([^\"\'\s<\n\)]*)/i',
	return preg_replace_callback( '/([^>\"\'=\]]{1}|pre>|p>|br>)(https?):\/\/([0-9a-zA-Z;,%\?\&\/:\.\-_=#~\+]+)/i',
		create_function(
		    '$matches',
		    'if(strlen($matches[3])>44) $ext="..."; return "$matches[1]<a href=\"$matches[2]://$matches[3]\">$matches[2]://".substr($matches[3],0,44)."${ext}</a>";'
		),
		$content );
}

//add_filter('the_content', 'the_content_script_filter');
function the_content_script_filter($content) {
//	return preg_replace_callback( '/<script\s([^>]*)>(.*)<\/script>/i',
	return preg_replace_callback( '/script(.*)script/i',
		create_function(
		    '$matches',
		    '$newtxt=preg_replace("/<\/p>/","",$matches[1]);
		     $newtxt=preg_replace("/<br \/>/","",$newtxt);
		     $newtxt=preg_replace("/<p>/","",$newtxt);
		    //return "<script tt $matches[1]  tt >$newtxt </script>";
		    return "script tt  $newtxt script";
'), $content);

}
?>
